﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Excel;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace LeafExcelImport
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void Log(string message)
        {
            listBox1.Items.Add(message);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //FileStream stream = File.Open(@"E:\TestData\VillageData.xlsx", FileMode.Open, FileAccess.Read);
            //IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
            //excelReader.IsFirstRowAsColumnNames = true;
            //DataSet reader = excelReader.AsDataSet();
            //DataTable table = reader.Tables[0];
            //dgView1.DataSource = table;

            //Log("Opening connection...");
            //string table = "PG";
            //try
            //{
            //    //con.Open();
            //    Log("Reading AG data...");
            //    string connectionString = "server=localhost;user=root;database=leaf;port=3306;";
            //    MySqlConnection con = new MySqlConnection(connectionString);
            //    MySqlBulkLoader blk = new MySqlBulkLoader(con);
            //    blk.TableName = table;
            //    blk.FieldTerminator = "\t";
            //    blk.LineTerminator = "\n";
            //    blk.FileName = @"E:\TestData\"+table+".txt";
            //    blk.NumberOfLinesToSkip = 1;

            //    try
            //    {
            //        con.Open();
            //        int count = blk.Load();
            //        Log(count + " rows uploaded");
            //        con.Close();
            //    }
            //    catch (Exception ex)
            //    {
            //        Log(ex.Message);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    Log(ex.Message);
            //}
        }
    }
}
